package com.cryptape.cita_wallet;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;
import android.widget.Toast;

import com.cryptape.cita_wallet.activity.BaseActivity;
import com.mangoworld.android.R;

/**
 * Created by dengming on 17/3/20.
 */

public class ExportPrivateKeyActivity extends BaseActivity {

    public static final String EXTRA_KEYSTORE = "extra_keystore";

    private String keystore;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_export_private_key);
        initView();
        initListener();
    }

//    public String exportPrivateKey(String keystorePath, String password) {
//        try {
//            Credentials credentials = WalletUtils.loadCredentials(password,keystorePath);
//            BigInteger privateKey = credentials.getEcKeyPair().getPrivateKey();
//            log.info("exportPrivateKey : " + privateKey.toString(16));
//            return privateKey.toString(16);
//        } catch (IOException | CipherException e) {
//            log.error("exportPrivateKey exception",e);
//        }
//        return null;
//    }


    private void initView() {
        keystore = getIntent().getStringExtra(EXTRA_KEYSTORE);
        TextView keystoreText = findViewById(R.id.message_text);
        keystoreText.setText(keystore);
    }

    private void initListener() {
        findViewById(R.id.export_copy).setOnClickListener(v -> {
            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData mClipData = ClipData.newPlainText("keystore", keystore);
            if (cm != null) {
                cm.setPrimaryClip(mClipData);
                Toast.makeText(mActivity, R.string.copy_success, Toast.LENGTH_SHORT).show();
            }
        });
    }
}